home *** CD-ROM | disk | FTP | other *** search
- Path: news.acns.nwu.edu!aragorn221
- From: llong@nwu.edu (Lorraine E. Long)
- Newsgroups: comp.lang.c
- Subject: Re: Help for a float problem
- Date: Sun, 18 Feb 96 03:20:40 GMT
- Organization: Northwestern University, Evanston, IL. USA
- Message-ID: <4g65u8$9dg_001@nuts.nwu.edu>
- References: <AMCHAVAN.96Jan25112007@ac2.hq.eso.org> <4f6tt6$rt1@news.cencom.net> <311A83D1.57A3@feith.com> <4fe4m4$f1c@news.ee.net> <4fgbss$nqm@ixnews6.ix.netcom.com> <9FEB199622285820@erich.triumf.ca>
- NNTP-Posting-Host: aragorn221.nuts.nwu.edu
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <9FEB199622285820@erich.triumf.ca>,
- bennett@erich.triumf.ca (P.Bennett) wrote:
- >In article <4fgbss$nqm@ixnews6.ix.netcom.com>, wzjn@ix.netcom.com (KPN )
- writes...
- >>Good Afternoon,
- >>
- >>Using æHow To Program C (second edition)Æ by Deitel & Deitel, IÆm
- >>trying to do on page 92, example 3.17. IÆm not sure, but believe that
- >>my problem is where to use a æfloatÆ.
- >>
- >>I want to ask the user to enter gallons used, which of course, could be
- >>12.8. However, with the same line, I want the user to enter æ-1Æ if
- >>they choose to end the program.
- >>
- >>The way it is written so far, the user can successfully exit the
- >>program with a -1. The user can also successfully enter whole numbers
- >>and get an answer. My problem arises when I enter (again) 12.8 ... the
- >>program goes in to an infinate loop! eh?
- >>
- >>Conversely, if I define gallons as a float, the program does not
- >>recognize the æ-1Æ as an end of program. eh?
- >>
- >
- >If you expect the user to enter a decimal value like 12.8 for gallons (or
- >miles), you must declare gallons as float.
- >
- >However, when the user enters -1 to quit, you will be caught by the fact that
- >floating point numbers are never exact (Although I would expect -1 to be), so
- >it is unwise to compare two floats for equality.
- >
- >You could compare their difference to some small number, or, for this
- problem,
- >simply consider any negative number as the signal to quit.
- >
- >
- >Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- >Internet: bennett@triumf.ca | of one another only when one can be
- >Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- >TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- >GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- >
- >
- >
- >
- >
- >
- >
- >
- >
-
-
- Lorraine E. Long
- Northwestern University, Evanston, IL. USA
- llong@nwu.edu
-